<?php
/**
 * SocialEngine
 *
 * @category   Application_Extensions
 * @package    Page
 * @copyright  Copyright Hire-Experts LLC
 * @license    http://www.hire-experts.com
 * @version    $Id: Controller.php 2010-08-31 16:05 idris $
 * @author     Idris
 */

/**
 * @category   Application_Extensions
 * @package    Page
 * @copyright  Copyright Hire-Experts LLC
 * @license    http://www.hire-experts.com
 */

class Page_Widget_ProfileMapController extends Engine_Content_Widget_Abstract
{
  public function indexAction()
  {
    // Get subject and check auth
    $this->view->subject = $subject = Engine_Api::_()->core()->getSubject('page');
    $page_id = $subject->getIdentity();
    
    $table = Engine_Api::_()->getDbTable('pages', 'page');
    $params = array('view' => 'map', 'page_id' => $page_id);
    $select = $table->getSelect($params);
    $page = $table->fetchRow($select);
    
   	$markers = array();
    if ($page->marker_id > 0){
	    $markers[0] = array(
				'marker_id' => $page->marker_id,
				'lat' => $page->latitude,
				'lng' => $page->longitude,
				'pages_id' => $page->page_id,
				'pages_photo' => $page->getPhotoUrl('thumb.normal'),
				'title' => $page->getTitle(),
				'desc' => substr($page->getDescription(),0,200),
	      'url' => $page->getHref()
			);
			
			$this->view->markers = json_encode($markers);
			$this->view->bounds = json_encode(Engine_Api::_()->getApi('gmap', 'page')->getMapBounds($markers));
    }else{
      $this->setNoRender();
      return ;
    }
  }
}